<template>
  <!--
        作者：luoyiming
        时间：2020-07-25
        描述：插件中心-视频-视频列表
    -->
  <div class="list">

    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form size="small" :inline="true" :model="searchForm" class="demo-form-inline">
        <el-form-item><el-input size="small" v-model="searchForm.productName" placeholder="請輸入直播商品名稱"></el-input></el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="Search" @click="searchSubmit">查詢</el-button>
          <el-button size="small" type="primary" icon="Plus" @click="openEdit">添加商品</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
          <el-table-column prop="name" label="名稱"></el-table-column>
          <el-table-column label="商品封面圖片">
            <template #default="scope">
              <img :src="scope.row.coverImgPath" width="30" height="30" />
            </template>
          </el-table-column>
          <el-table-column prop="priceTypeText" label="價格類型"></el-table-column>
          <el-table-column prop="priceText" label="價格" width="200"></el-table-column>
          <el-table-column prop="auditStatusText" label="微信審核狀態" width="100"></el-table-column>
          <el-table-column prop="createTime" label="創建時間"></el-table-column>
          <el-table-column fixed="right" label="操作">
            <template #default="scope">
              <el-button type="text" size="small" @click="openEdit(scope.row)">編輯</el-button>
              <el-button type="text" size="small" @click="delClick(scope.row)">刪除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background :current-page="curPage" :page-size="pageSize" layout="total, prev, pager, next, jumper" :total="totalDataNumber"></el-pagination>
      </div>
    </div>
    <!--查看房间商品-->
    <Edit ref="editRef" @get-table-list="getTableList"></Edit>
  </div>
</template>

<script>
import wxLiveApi from '@/api/wxlive.js';
import Edit from './edit.vue';
// import Add from './add.vue'
export default {
  components: {
    // Add,
    Edit
  },
  data() {
    return {
      /*是否加载完成*/
      loading: false,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      searchForm: {
        orderNo: '',
        roomName: '',
        realName: ''
      }
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    openEdit(row) {
      this.$refs['editRef'].open(row);
    },
    /*搜索*/
    searchSubmit() {
      this.curPage = 1;
      this.getTableList();
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.getTableList();
    },
    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = self.searchForm;
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      self.loading = true;
      wxLiveApi.getProductList(Params, true).then(res => {
        self.loading = false;
        self.tableData = res.data.records;
        self.totalDataNumber = res.data.total;
      }).catch(error => {
        self.loading = false;
      });
    },
    /*删除*/
    delClick: function (row) {
      let self = this;
      ElMessageBox.confirm("刪除後不可恢復，確認刪除該記錄嗎？", "提示", {
        type: 'warning'
      }).then(() => {
        wxLiveApi.deleteProduct({
          productId: row.appProductId
        }).then(data => {
          ElMessage({
            message: "刪除成功",
            type: 'success'
          });
          self.getTableList();
        });
      });
    }
  }
};
</script>

